Method and apparatus for providing packed shift operations in a processor

ABSTRACT

A method and apparatus for providing, in a processor, a shift operation on a packed data element having multiple values. The apparatus having multiple muxes, each of the multiple muxes having a first input, a second input, a select input and an output. Each of the multiple bits that represent a shifted packed intermediate result on a first bus is coupled to the corresponding first input. Each of the multiple bits representing a replacement bit for one of the multiple values is coupled to a corresponding second input. Each of the multiple bits driven by a correction circuit is coupled to a corresponding select input. Each output corresponds to a bit of a shifted packed result.

RELATED APPLICATIONS

This is a continuation of application Ser. No. 11/140,454 filed May 27,2005, now U.S. Pat. No. 7,117,232; which is a continuation ofapplication Ser. No. 10/623,062, filed Jul. 18, 2003, now U.S. Pat. No.6,901,420; which is a continuation of application Ser. No. 09/747,122,filed Dec. 22, 2000, now U.S. Pat. No. 6,631,389; which is acontinuation of application Ser. No. 08/610,495 filed Mar. 4, 1996, nowU.S. Pat. No. 6,275,834; which is a continuation-in-part of applicationSer. No. 08/349,730 filed Dec. 1, 1994, now abandoned.

BACKGROUND OF THE INVENTION

1. Field of the Invention

In particular, the present invention describes an apparatus forperforming arithmetic operations using a single control signal tomanipulate multiple data elements. The present invention allowsexecution of shift operations on packed data types.

2. Description of Related Art

Today, most personal computer systems operate with one instruction toproduce one result. Performance increases are achieved by increasingexecution speed of instructions and the processor instructioncomplexity; known as Complex Instruction Set Computer (CISC). Suchprocessors as the Intel 80286™ microprocessor, available from IntelCorp. of Santa Clara, Calif., belong to the CISC category of processor.

Previous computer system architecture has been optimized to takeadvantage of the CISC concept. Such systems typically have data busesthirty-two bits wide. However, applications targeted at computersupported cooperation (CSC—the integration of teleconferencing withmixed media data manipulation), 2D/3D graphics, image processing, videocompression/decompression, recognition algorithms and audio manipulationincrease the need for improved performance. But, increasing theexecution speed and complexity of instructions is only one solution.

One common aspect of these applications is that they often manipulatelarge amounts of data where only a few bits are important. That is, datawhose relevant bits are represented in much fewer bits than the size ofthe data bus. For example, processors execute many operations on eightbit and sixteen bit data (e.g., pixel color components in a video image)but have much wider data busses and registers. Thus, a processor havinga thirty-two bit data bus and registers, and executing one of thesealgorithms, can waste up to seventy-five percent of its data processing,carrying and storage capacity because only the first eight bits of dataare important.

As such, what is desired is a processor that increases performance bymore efficiently using the difference between the number of bitsrequired to represent the data to be manipulated and the actual datacarrying and storage capacity of the processor.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates an embodiment of the computer system using theapparatus of the present invention.

FIG. 2 illustrates an embodiment of the processor of the presentinvention.

FIG. 3 is a flow diagram illustrating the general steps used by theprocessor to manipulate data in the register file.

FIG. 4 a illustrates memory data types.

FIG. 4 b, FIG. 4 c and FIG. 4 d illustrate in-register integer datarepresentations.

FIG. 5 a illustrates packed data-types.

FIG. 5 b, FIG. 5 c and FIG. 5 d illustrate in-register packed datarepresentations.

FIG. 6 a illustrates a control signal format used in the computer systemto indicate the use of packed data.

FIG. 6 b illustrates a second control signal format that can be used inthe computer system to indicate the use of packed data.

FIG. 7 illustrates one embodiment of a method followed by a processorwhen performing a shift operation on packed data.

FIG. 8 illustrates one embodiment of a Packed Shift circuit.

FIG. 9 illustrates another embodiment of a Packed Shift circuit.

FIG. 10 illustrates an embodiment of a portion of the logic to identifywhich bits of the barrel shifted result should be corrected (Fixshift).

FIG. 11 illustrates an embodiment of a barrel shifter.

FIG. 12 illustrates an embodiment of a mux for a barrel shifter.

FIG. 13 illustrates another embodiment of a method of performing apacked shift operation.

DETAILED DESCRIPTION

A processor having shift operations that operate on multiple dataelements is described. In the following description, numerous specificdetails are set forth such as circuits, etc., in order to provide athorough understanding of the present invention. In other instances,well-known structures and techniques have not been shown in detail inorder not to unnecessarily obscure the present invention.

Definitions

To provide a foundation for understanding the description of theembodiments of the present invention, the following definitions areprovided.

Bit X through Bit Y: defines a subfield of binary number. For example,bit six through bit zero of the byte 001110102 (shown in base two)represent the subfield 1110102. The ‘2’ following a binary numberindicates base 2. Therefore, 10002 equals 810, while F16 equals 1510.R_(x): is a register. A register is any device capable of storing andproviding data. Further functionality of a register is described below.A register is not necessarily part of the processor's package. DEST: isa data address. SRC1: is a data address. SRC2: is a data address.Result: is the data to be stored in the register addressed by DEST.Source1: is the data stored in the register addressed by SRC1. Source2:is the data stored in the register addressed by SRC2.Computer System

Referring to FIG. 1, a computer system upon which an embodiment of thepresent invention can be implemented is shown as computer system 100.Computer system 100 comprises a bus 101, or other communicationshardware and software, for communicating information, and a processor109 coupled with bus 101 for processing information. Computer system 100further comprises a random access memory (RAM) or other dynamic storagedevice (referred to as main memory 104), coupled to bus 101 for storinginformation and instructions to be executed by processor 109. Mainmemory 104 also may be used for storing temporary variables or otherintermediate information during execution of instructions by processor109. Computer system 100 also comprises a read only memory (ROM) 106,and/or other static storage device, coupled to bus 101 for storingstatic information and instructions for processor 109. Data storagedevice 107 is coupled to bus 101 for storing information andinstructions. Memory includes any data storage medium, such as mainmemory 104, cache memory, registers, ROM, and other static storagedevices.

Furthermore, a data storage device 107, such as a magnetic disk oroptical disk, and its corresponding disk drive, can be coupled tocomputer system 100. Computer system 100 can also be coupled via bus 101to a display device 121 for displaying information to a computer user.Display device 121 can include a frame buffer, specialized graphicsrendering devices, a cathode ray tube (CRT), and/or a flat paneldisplay. An alphanumeric input device 122, including alphanumeric andother keys, is typically coupled to bus 101 for communicatinginformation and command selections to processor 109. Another type ofuser input device is cursor control 123, such as a mouse, a trackball, apen, a touch screen, or cursor direction keys for communicatingdirection information and command selections to processor 109, and forcontrolling cursor movement on display device 121. This input devicetypically has two degrees of freedom in two axes, a first axis (e.g., x)and a second axis (e.g., y), which allows the device to specifypositions in a plane. However, this invention should not be limited toinput devices with only two degrees of freedom.

Another device which may be coupled to bus 101 is a hard copy device 124which may be used for printing instructions, data, or other informationon a medium such as paper, film, or similar types of media.Additionally, computer system 100 can be coupled to a device for soundrecording, and/or playback 125, such as an audio digitizer coupled to amicrophone for recording information. Further, the device may include aspeaker which is coupled to a digital to analog (D/A) converter forplaying back the digitized sounds.

Also, computer system 100 can be a terminal in a computer network (e.g.,a LAN). Computer system 100 would then be a computer subsystem of acomputer system including a number of networked devices. Computer system100 optionally includes video digitizing device 126. Video digitizingdevice 126 can be used to capture video images that can be transmittedto others on the computer network.

Computer system 100 is useful for supporting computer supportedcooperation (CSC—the integration of teleconferencing with mixed mediadata manipulation), 2D/3D graphics, image processing, videocompression/decompression, recognition algorithms and audiomanipulation.

Processor

FIG. 2 illustrates a detailed diagram of processor 109. Processor 109can be implemented on one or more substrates using any of a number ofprocess technologies, such as, BiCMOS, CMOS, and NMOS.

Processor 109 comprises a decoder 202 for decoding control signals anddata used by processor 109. Data can then be stored in register file 204via internal bus 205. As a matter of clarity, the registers of anembodiment should not be limited in meaning to a particular type ofcircuit. Rather, a register of an embodiment need only be capable ofstoring and providing data, and performing the functions describedherein.

Depending on the type of data, the data may be stored in integerregisters 201, registers 209, status registers 208, or instructionpointer register 211. Other registers can be included in the registerfile 204, for example, floating point registers. In one embodiment,integer registers 201 store thirty-two bit integer data. In oneembodiment, registers 209 contains eight registers, R₀ 212 a through R₇212 h. Each register in registers 209 is sixty-four bits in length. R₀212 a, R₁ 212 b and R₂ 212 c are examples of individual registers inregisters 209. Thirty-two bits of a register in registers 209 can bemoved into an integer register in integer registers 201. Similarly, avalue in an integer register can be moved into thirty-two bits of aregister in registers 209.

Status registers 208 indicate the status of processor 109. Instructionpointer register 211 stores the address of the next instruction to beexecuted. Integer registers 201, registers 209, status registers 208,and instruction pointer register 211 all connect to internal bus 205.Any additional registers would also connect to the internal bus 205.

In another embodiment, some of these registers can be used for twodifferent types of data. For example, registers 209 and integerregisters 201 can be combined where each register can store eitherinteger data or packed data. In another embodiment, registers 209 can beused as floating point registers. In this embodiment, packed data can bestored in registers 209 or floating point data. In one embodiment, thecombined registers are sixty-four bits in length and integers arerepresented as sixty-four bits. In this embodiment, in storing packeddata and integer data, the registers do not need to differentiatebetween the two data types.

Functional unit 203 performs the operations carried out by processor109. Such operations may include shifts, addition, subtraction andmultiplication, etc. Functional unit 203 connects to internal bus 205.Cache 206 is an optional element of processor 109 and can be used tocache data and/or control signals from, for example, main memory 104.Cache 206 is connected to decoder 202, and is connected to receivecontrol signal 207.

FIG. 3 illustrates the general operation of processor 109. That is, FIG.3 illustrates the steps followed by processor 109 while performing anoperation on packed data, performing an operation on unpacked data, orperforming some other operation. For example, such operations include aload operation to load a register in register file 204 with data fromcache 206, main memory 104, read only memory (ROM) 106, or data storagedevice 107. In one embodiment of the present invention, processor 109supports most of the instructions supported by the Intel 80486™,available from Intel Corporation of Santa Clara, Calif. In anotherembodiment of the present invention, processor 109 supports all theoperations supported by the Intel 80486™, available from IntelCorporation of Santa Clara, Calif. In another embodiment of the presentinvention, processor 109 supports all the operations supported by thePentium™ processor, the Intel 80486™ processor, the 80386™ processor,the Intel 80286™ processor, and the Intel 8086™ processor, all availablefrom Intel Corporation of Santa Clara, Calif. In another embodiment ofthe present invention, processor 109 supports all the operationssupported in the IA™—Intel Architecture, as defined by Intel Corporationof Santa Clara, Calif. (see Microprocessors, Intel Data Books volume 1and volume 2, 1992 and 1993, available from Intel of Santa Clara,Calif.). Generally, processor 109 can support the present instructionset for the Pentium™ processor, but can also be modified to incorporatefuture instructions, as well as those described herein. What isimportant is that processor 109 can support previously used operationsin addition to the operations described herein.

At step 301, the decoder 202 receives a control signal 207 from eitherthe cache 206 or bus 101. Decoder 202 decodes the control signal todetermine the operations to be performed.

Decoder 202 accesses the register file 204, or a location in anothermemory, at step 302. Registers in the register file 204, or memorylocations in another memory, are accessed depending on the registeraddress specified in the control signal 207. For example, for anoperation on packed data, control signal 207 can include SRC1, SRC2 andDEST register addresses. SRC1 is the address of the first sourceregister. SRC2 is the address of the second source register. In somecases, the SRC2 address is optional as not all operations require twosource addresses. If the SRC2 address is not required for an operation,then only the SRC1 address is used. DEST is the address of thedestination register where the result data is stored. In one embodiment,SRC1 or SRC2 is also used as DEST. SRC1, SRC2 and DEST are describedmore fully in relation to FIG. 6 a and FIG. 6 b. The data stored in thecorresponding registers is referred to as Source1, Source2, and Resultrespectively. Each of these data is sixty-four bits in length.

In another embodiment of the present invention, any one, or all, ofSRC1, SRC2 and DEST, can define a memory location in the addressablememory space of processor 109. For example, SRC1 may identify a memorylocation in main memory 104 while SRC2 identifies a first register ininteger registers 201, and DEST identifies a second register inregisters 209. For simplicity of the description herein, references aremade to the accesses to the register file 204, however, these accessescould be made to another memory instead.

In another embodiment of the present invention, the operation code onlyincludes two addresses, SRC1 and SRC2. In this embodiment, the result ofthe operation is stored in the SRC1 or SRC2 register. That is SRC1 (orSRC2) is used as the DEST. This type of addressing is compatible withprevious CISC instructions having only two addresses. This reduces thecomplexity in the decoder 202. Note, in this embodiment, if the datacontained in the SRC1 register is not to be destroyed, then that data iscopied into another register before the execution of the operation. Thecopying would require an additional instruction. To simplify thedescription herein, the three address addressing scheme will bedescribed (i.e. SRC1, SRC2, and DEST). However, it should be rememberedthat the control signal, in one embodiment, may only include SRC1 andSRC2, and that SRC1 (or SRC2) identifies the destination register.

Where the control signal requires an operation, at step 303, functionalunit 203 will be enabled to perform this operation on accessed data fromregister file 204. Once the operation has been performed in functionalunit 203, at step 304, the result is stored back into register file 204or another memory according to requirements of control signal 207.

Data Storage and Formats

FIG. 4 a illustrates some of the data formats as may be used in thecomputer system of FIG. 1. These data formats are fixed point. Processor109 can manipulate these data formats. Multimedia algorithms often usethese data formats. A byte 401 contains eight bits of information. Aword 402 contains sixteen bits of information, or two bytes. Adoubleword 403 contains thirty-two bits of information, or four bytes.Thus, processor 109 executes control signals that may operate on any oneof these memory data formats.

In the following description, references to bit, byte, word, anddoubleword subfields are made. For example, bit six through bit zero ofthe byte 00111010₂ (shown in base 2) represent the subfield 111010₂.

FIG. 4 b through FIG. 4 d illustrate in-register representations used inone embodiment of the present invention. For example, unsigned bytein-register representation 410 can represent data stored in a registerin integer registers 201. In one embodiment, a register in integerregisters 201 is sixty-four bits in length. In another embodiment, aregister in integer registers 201 is thirty-two bits in length. For thesimplicity of the description, the following describes sixty-four bitinteger registers, however, thirty-two bit integer registers can beused. In other embodiments, other sizes of registers may be used.

Unsigned byte in-register representation 410 illustrates processor 109storing an unsigned byte in integer registers 201. The first eight bits,bit seven through bit zero, in that register are dedicated to the databyte 401. These bits are shown as {b}. To properly represent this byte,the remaining 56 bits must be zero. For a signed byte in-registerrepresentation 411, integer registers 201 store the magnitude of asigned byte in the first seven bits, bit six through bit zero. Theseventh bit represents the sign bit, shown as an {s}. Each of theremaining bits, bit sixty-three through bit eight, contain the sign bit.

Unsigned word in-register representation 412 is stored in one registerof integer registers 201. Bit fifteen through bit zero contain anunsigned word. These bits are shown as {w}. To properly represent thisword, the remaining bit sixty-three through bit sixteen must be zero.The magnitude of a signed word is stored in bit fourteen through bitzero as shown in the signed word in-register representation 413. Each ofthe remaining bits, bit sixty-three through bit eight, contain the signbit.

A doubleword can be stored as an unsigned doubleword in-registerrepresentation 414 or a signed doubleword in-register representation415. Bit thirty-one through bit zero of an unsigned doublewordin-register representation 414 contain an unsigned doubleword. Thesebits are shown as {d}. To properly represent this unsigned doubleword,the remaining bit sixty-three through bit thirty-two must be zero.Integer registers 201 stores the magnitude of a signed doubleword in bitthirty through bit zero as shown in signed doubleword in-registerrepresentation. Each of the remaining bits, bit sixty-three through biteight, contain the sign bit.

As indicated by the above FIG. 4 b through FIG. 4 d, storage of somedata types in a sixty-four bit wide register is an inefficient method ofstorage. For example, for storage of an unsigned byte in-registerrepresentation 410 bit sixty-three through bit eight must be zero, whileonly bit seven through bit zero may contain non-zero bits. Thus, aprocessor storing a byte in a sixty-four bit register uses only 12.5% ofthe register's capacity. Similarly, only the first few bits ofoperations performed by functional unit 203 will be important.

FIG. 5 a illustrates the data formats for packed data. Three packed dataformats are illustrated; packed byte 501, packed word 502, and packeddoubleword 503. Packed byte, in one embodiment of the present invention,is sixty-four bits long containing eight data elements. Each dataelement is one byte long. Generally, a data element is an individualpiece of data that is stored in a single register (or memory location)with other data elements of the same length. In one embodiment of thepresent invention, the number of data elements stored in a register issixty-four bits divided by the length in bits of a data element.

Packed word 502 is sixty-four bits long and contains four word 402 dataelements. Each word 402 data element contains sixteen bits ofinformation.

Packed doubleword 503 is sixty-four bits long and contains twodoubleword 403 data elements. Each doubleword 403 data element containsthirty-two bits of information.

FIG. 5 b through FIG. 5 d illustrate the in-register packed data storagerepresentation. Unsigned packed byte in-register representation 510illustrates the storage of packed byte 501 in one of the registers R₀212 a through R_(n) 212 af. Information for each byte data element isstored in bit seven through bit zero for byte zero, bit fifteen throughbit eight for byte one, bit twenty-three through bit sixteen for bytetwo, bit thirty-one through bit twenty-four for byte three, bitthirty-nine through bit thirty-two for byte four, bit forty-seventhrough bit forty for byte five, bit fifty-five through bit forty-eightfor byte six and bit sixty-three through bit fifty-six for byte seven.Thus, all available bits are used in the register. This storagearrangement increases the storage efficiency of the processor. As well,with eight data elements accessed, one operation can now be performed oneight data elements simultaneously. Signed packed byte in-registerrepresentation 511 is similarly stored in a register in registers 209.Note that only the eighth bit of every byte data element is thenecessary sign bit; other bits may or may not be used to indicate sign.

Unsigned packed word in-register representation 512 illustrates how wordthree through word zero are stored in one register of registers 209. Bitfifteen through bit zero contain the data element information for wordzero, bit thirty-one through bit sixteen contain the information fordata element word one, bit forty-seven through bit thirty-two containthe information for data element word two and bit sixty-three throughbit forty-eight contain the information for data element word three.Signed packed word in-register representation 513 is similar to theunsigned packed word in-register representation 512. Note that only thesixteenth bit of each word data element contains the necessary signindicator.

Unsigned packed doubleword in-register representation 514 shows howregisters 209 store two doubleword data elements. Doubleword zero isstored in bit thirty-one through bit zero of the register. Doublewordone is stored in bit sixty-three through bit thirty-two of the register.Signed packed doubleword in-register representation 515 is similar tounsigned packed doubleword in-register representation 514. Note that thenecessary sign bit is the thirty-second bit of the doubleword dataelement.

As mentioned previously, registers 209 may be used for both packed dataand integer data. In this embodiment of the present invention, theindividual programming processor 109 may be required to track whether anaddressed register, R₀ 212 a for example, is storing packed data orsimple integer/fixed point data. In an alternative embodiment, processor109 could track the type of data stored in individual registers ofregisters 209. This alternative embodiment could then generate errorsif, for example, a packed addition operation were attempted onsimple/fixed point integer data.

Control Signal Formats

The following describes one embodiment of control signal formats used byprocessor 109 to manipulate packed data. In one embodiment of thepresent invention, control signals are represented as thirty-two bits.Decoder 202 may receive control signal 207 from bus 101. In anotherembodiment, decoder 202 can also receive such control signals from cache206.

FIG. 6 a illustrates a general format for a control signal operating onpacked data. Operation field OP 601, bit thirty-one through bittwenty-six, provides information about the operation to be performed byprocessor 109; for example, packed addition, packed subtraction, etc.SRC1 602, bit twenty-five through twenty, provides the source registeraddress of a register in registers 209. This source register containsthe first packed data, Source1, to be used in the execution of thecontrol signal. Similarly, SRC2 603, bit nineteen through bit fourteen,contains the address of a register in registers 209. This second sourceregister contains the packed data, Source2, to be used during executionof the operation. DEST 605, bit five through bit zero, contains theaddress of a register in registers 209. This destination register willstore the result packed data, Result, of the packed data operation.

Control bits SZ 610, bit twelve and bit thirteen, indicates the lengthof the data elements in the first and second packed data sourceregisters. If SZ 610 equals 01₂, then the packed data is formatted aspacked byte 501. If SZ 610 equals 10₂, then the packed data is formattedas packed word 502. SZ 610 equaling 00₂ or 11₂ is reserved, however, inanother embodiment, one of these values could be used to indicate thatthe packed data is to be formatted as a packed doubleword 503.

Control bit T 611, bit eleven, indicates whether the operation is to becarried out with saturate mode. If T 611 equals one, then a saturatingoperation is performed. If T 611 equals zero, then a nonsaturatingoperation is performed. Saturating operations will be described later.

Control bit S 612, bit ten, indicates the use of a signed operation. IfS 612 equals one, then a signed operation is performed. If S 612 equalszero, then an unsigned operation is performed.

FIG. 6 b illustrates a second general format for a control signaloperating on packed data. This format corresponds with the generalinteger opcode format described in the “Pentium™ Processor Family User'sManual,” available from Intel Corporation, Literature Sales, P.O. Box7641, Mt. prospect, IL, 60056-7641. Note that OP 601, SZ 610, T 611, andS 612 are all combined into one large field. For some control signals,bits three through five are SRC1 602. In one embodiment, where there isa SRC1 602 address, then bits three through five also correspond to DEST605. In an alternate embodiment, where there is a SRC2 603 address, thenbits zero through two also correspond to DEST 605. For other controlsignals, like a packed shift immediate operation, bits three throughfive represent an extension to the opcode field. In one embodiment, thisextension allows a programmer to include an immediate value with thecontrol signal, such as a shift count value. In one embodiment, theimmediate value follows the control signal. This is described in moredetail in the “Pentium™ Processor Family User's Manual,” in appendix F,pages F-1 through F-3. Bits zero through two represent SRC2 603. Thisgeneral format allows register to register, memory to register, registerby memory, register by register, register by immediate, register tomemory addressing. Also, in one embodiment, this general format cansupport integer register to register, and register to integer registeraddressing.

Description of Saturate/Unsaturate

As mentioned previously, T 611 indicates whether operations optionallysaturate. Where the result of an operation, with saturate enabled,overflows or underflows the range of the data, the result is clamped.Clamping means setting the result to a maximum or minimum value should aresult exceed the range's maximum or minimum value. In the case ofunderflow, saturation clamps the result to the lowest value in the rangeand in the case of overflow, to the highest value. The allowable rangefor each data format is shown in Table 1.

TABLE 1 Data Format Minimum Value Maximum Value Unsigned Byte    0 255Signed Byte  −128 127 Unsigned Word    0 65535 Signed Word −32768 32767Unsigned Doubleword    0 2³² − 1 Signed Doubleword    −2³¹ 2³¹ − 1

As mentioned above, T 611 indicates whether saturating operations arebeing performed. Therefore, using the unsigned byte data format, if anoperation's result is equal to 258 and saturation was enabled, then theresult would be clamped to 255 before being stored into the operation'sdestination register. Similarly, if an operation's result is equal to−32999 and processor 109 used signed word data format with saturationenabled, then the result would be clamped to −32768 before being storedinto the operation's destination register.

Shift Operation

In one embodiment of the present invention, the performance of CSCapplications is improved by not only supporting a standard CISCinstruction set (unpacked data operations), but by supporting a shiftoperation on packed data. The packed shift can be used to increase thespeed of fixed-point implements of Fast Fourier Transforms, CosineTransforms, and other digital image and audio signal processingalgorithms.

In one embodiment of the present invention, the SRC1 register containsthe data (Source1) to be shifted, the SRC2 register contains the data(Source2) representing the shift count, and DEST register will containthe result of the shift (Result). That is, Source1 will have each dataelement independently shifted by the shift count. In one embodiment,Source2 is interpreted as an unsigned 64 bit scalar. In anotherembodiment, Source2 is packed data and contains shift counts for eachcorresponding data element in Source1.

In one embodiment of the present invention, both arithmetic shifts andlogical shifts are supported. An arithmetic shift, shifts the bits ofeach data element down by a specified number, and fills the high orderbit of each data element with the initial value of the sign bit. A shiftcount greater than seven for packed byte data, greater than fifteen forpacked word data, or greater than thirty-one for packed doubleword,causes the each Result data element to be filled with the initial valueof the sign bit. A logical shift can operate by shifting bits up ordown. In a shift right logical, the high order bits of each data elementare filled with zeroes. A shift left logical causes the leastsignificant bits of each data element to be filled with zeroes.

In one embodiment of the present invention, a shift right arithmetic,the shift right logical, and the shift left logical operations aresupported for packed bytes and packed words. In another embodiment ofthe present invention, these operations are supported for packeddoublewords also.

FIG. 7 illustrates one embodiment of a method of performing a shiftoperation on packed data. This embodiment can be implemented in theprocessor 109 of FIG. 2.

At step 701, decoder 202 decodes control signal 207 received byprocessor 109. Thus, decoder 202 decodes: the operation code for theappropriate shift operation; SRC1 602, SRC2 603 and DEST 605 addressesin integer registers 209; saturate/unsaturate (not necessarily neededfor shift operations), signed/unsigned (again not necessarily needed),and length of the data elements in the packed data.

At step 702, via internal bus 205, decoder 202 accesses integerregisters 209 in register file 204 given the SRC1 602 and SRC2 603addresses. Integer registers 209 provides functional unit 203 with thepacked data stored in the SRC1 602 register (Source1), and the scalarshift count stored in SRC2 603 register (Source2). That is, integerregisters 209 communicate the packed data to functional unit 203 viainternal bus 205.

At step 703, decoder 202 enables functional unit 203 to perform theappropriate packed shift operation. Decoder 202 further communicates,via internal bus 205, the size of data elements, the type of shiftoperation, and the direction of the shift (for logical shifts).

At step 710, the size of the data element determines which step is to beexecuted next. If the size of the data elements is eight bits (bytedata), then functional unit 203 performs step 712. However, if the sizeof the data elements in the packed data is sixteen bits (word data),then functional unit 203 performs step 714. In one embodiment, onlyeight bit and sixteen bit data element size packed shifts are supported.However, in another embodiment, a thirty-two bit data element sizepacked shift is also supported. In other embodiments, other size dataelements may be supported.

Assuming the size of the data elements is eight bits, then step 712 isexecuted. In step 712, the following is performed. Source1 bits seventhrough zero are shifted by the shift count (Source2 bits sixty-threethrough zero) generating Result bits seven through zero. Source1 bitsfifteen through eight are shifted by the shift count generating Resultbits fifteen through eight. Source1 bits twenty-three through sixteenare shifted by the shift count generating Result bits twenty-threethrough sixteen. Source1 bits thirty-one through twenty-four are shiftedby the shift count generating Result bits thirty-one throughtwenty-four. Source1 bits thirty-nine through thirty-two are shifted bythe shift count generating Result bits thirty-nine through thirty-two.Source1 bits forty-seven through forty are shifted by the shift countgenerating Result forty-seven through forty. Source1 bits fifty-fivethrough forty-eight are shifted by the shift count generating Resultbits fifty-five through forty-eight. Source1 bits sixty-three throughfifty-six are shifted by the shift count generating Result bitssixty-three through fifty-six.

Assuming the size of the data elements is sixteen bits, then step 714 isexecuted. In step 714, the following is performed. Source1 bits fifteenthrough zero are shifted by the shift count generating Result bitsfifteen through zero. Source1 bits thirty-one through sixteen areshifted by the shift count generating Result bits thirty-one throughsixteen. Source1 bits forty-seven through thirty-two are shifted by theshift count generating Result bits forty-seven through thirty-two.Source1 bits sixty-three through forty-eight are shifted by the shiftcount generating Result bits sixty-three through forty-eight.

In one embodiment, the shifts of step 712 are performed simultaneously.However, in another embodiment, these shifts are performed serially. Inanother embodiment, some of these shifts are performed simultaneouslyand some are performed serially. This discussion applies to the shiftsof step 714 as well.

At step 720, the Result is stored in the DEST register.

Table 2 illustrates the in-register representation of packed shift rightarithmetic operation. The first row of bits is the packed datarepresentation of Source1. The second row of bits is the datarepresentation of Source2. The third row of bits is the packed datarepresentation of the Result. The number below each data element bit isthe data element number. For example, Source1 data element three is10000000₂.

TABLE 2 00101010 01010101 01010101 11111111 10000000 01110000 1000111110001000 7 6 5 4 3 2 1 0 Shift   Shift   Shift   Shift   Shift   Shift  Shift   Shift   00000000 00000000 00000000 00000000 00000000 0000000000000000 00000100 =   =   =   =   =   =   =   =   00000010 0000010100000101 11111111 11110000 00000111 11111000 11111000 7 6 5 4 3 2 1 0

Table 3 illustrates the in-register representation of packed shift rightlogical operation on packed byte data.

TABLE 3 00101010 01010101 01010101 11111111 10000000 01110000 1000111110001000 7 6 5 4 3 2 1 0 Shift   Shift   Shift   Shift   Shift   Shift  Shift   Shift   00000000 00000000 00000000 00000000 00000000 0000000000000000 00000011 =   =   =   =   =   =   =   =   00000101 0000101000001010 00011111 00010000 00001110 00010001 00010001 7 6 5 4 3 2 1 0

Table 4 illustrates the in-register representation of packed shift leftlogical operation on packed byte data.

TABLE 4 00101010 01010101 01010101 11111111 10000000 01110000 1000111110001000 7 6 5 4 3 2 1 0 Shift   Shift   Shift   Shift   Shift   Shift  Shift   Shift   00000000 00000000 00000000 00000000 00000000 0000000000000000 00000011 =   =   =   =   =   =   =   =   01010000 1010100010101000 11111000 00000000 10000000 01111000 01000000 7 6 5 4 3 2 1 0Circuit Descriptions

The convention followed in the subsequent descriptions of circuits isthat the bus names correspond to the signal names on that bus. Forexample, a Source1 signal is on a Source1 bus. Busses with multiple bitsmay be designated with particular bit ranges. For example,Source1[31:16] indicates that the bus corresponds to bits 31 through 16of the Source1 bus. The whole bus may be referred to as the Source1 busor Source1[63:0] (for a 64 bit bus). The complement of a signal may bereferred to by appending an “#” after the signal name. For example, thecomplement of the Source1 signal on the Source1 bus is the Source1#signal on the Source1# bus.

Packed Shift Circuit

In one embodiment, the shift operation can occur on multiple dataelements in the same number of clock cycles as a single shift operationon unpacked data. To achieve execution in the same number of clockcycles, parallelism is used. That is, registers are simultaneouslyinstructed to perform the shift operation on the data elements. This isdiscussed in more detail below. FIG. 8 illustrates one embodiment of aportion of a circuit that can perform a shift operation on packed datain the same number of clock cycles as a shift operation on unpackeddata.

FIG. 8 illustrates the use of a modified byte slice shift circuit, byteslice stage_(i) 899. Each byte slice, except for the most significantdata element byte slice, includes a shift unit and bit control. The mostsignificant data element byte slice need only have a shift unit.

Shift unit_(i) 811 and shift unit_(i+1) 871 each allow eight bits fromSource1 to be shifted by the shift count. In one embodiment, each shiftunit operates like a known eight bit shift circuit. Each shift unit hasa Source1 input, a Source2 input, a control input, a next stage signal,a last stage signal, and a result output. Therefore, shift unit_(i) 811has Source1_(i) 831 input, Source2[63:0] 833 input, control_(i) 801input, next stage_(i) 813 signal, last stage_(i) 812 input, and a resultstored in result register_(i) 851. Therefore, shift unit_(i+1) 871 hasSource1_(i+1) 832 input, Source2[63:0] 833 input, control_(i+1) 802input, next stage_(i+1) 873 signal, last stage_(i+1) 872 input, and aresult stored in result register_(i+1) 852.

The Source1 input is typically an eight bit portion of Source1. Theeight bits represents the smallest type of data element, one packed bytedata element. Source2 input represents the shift count. In oneembodiment, each shift unit receives the same shift count fromSource2[63:0] 833. Operation control 800 transmits control signals toenable each shift unit to perform the required shift. The controlsignals are determined from the type of shift (arithmetic/logical) andthe direction of the shift. The next stage signal is received from thebit control for that shift unit. The shift unit will shift the mostsignificant bit out/in on the next stage signal, depending on thedirection of the shift (left/right). Similarly, each shift unit willshift the least significant bit out/in on the last stage signal,depending on the direction of the shift (right/left). The last stagesignal being received from the bit control unit of the previous stage.The result output represents the result of the shift operation on theportion of Source1 the shift unit is operating upon.

Bit control_(i) 820 is enabled from operation control 800 via packeddata enable_(i) 806. Bit control_(i) 820 controls next stage_(i) 813 andlast stage_(i+1) 872. Assume, for example, shift unit_(i) 811 isresponsible for the eight least significant bits of Source1, and shiftunit_(i+1) 871 is responsible for the next eight bits of Source1. If ashift on packed bytes is performed, bit control_(i) 820 will not allowthe least significant bit from shift unit_(i+1) 871 to be communicatedwith the most significant bit of shift unit_(i) 811. However, a shift onpacked words is performed, then bit control_(i) 820 will allow the leastsignificant bit from shift unit_(i+)1 871 to be communicated with themost significant bit of shift unit_(i) 811.

For example, in Table 5, a packed byte arithmetic shift right isperformed. Assume that shift unit_(i+1) 871 operates on data elementone, and shift unit_(i) 811 operates on data element zero. Shiftunit_(i+1) 871 shifts its least significant bit out. However operationcontrol 800 will cause bit control_(i) 820 to stop the propagation ofthat bit, received from last stage_(i+1) 821, to next stage_(i) 813.Instead, shift unit_(i) 811 will fill the high order bits with the signbit, Source1 [7].

TABLE 5 . . . . . . . . . . . . . . . . . . 00001110 10001000 7 6 5 4 32 1 0 Shift   Shift   Shift   Shift   Shift   Shift   Shift   Shift   .. . . . . . . . . . . . . . . . . . . . 00000001 =   =   =   =   =   =  =   =   . . . . . . . . . . . . . . . . . . 00000111 11000100 7 6 5 4 32 1 0

However, if a packed word arithmetic shift is performed, then the leastsignificant bit of shift unit_(i+1) 871 will be communicated to the mostsignificant bit of shift unit_(i) 811. Table 6 illustrates this result.This communication would be allowed for packed doubleword shifts aswell.

TABLE 6 . . . . . . . . . 00001110 10001000 3 2 1 0 Shift   Shift  Shift   Shift . . . . . . . . . 00000001 =   =   =   = . . . . . . . . .00000111 01000100 3 2 1 0

Each shift unit is optionally connected to a result register. The resultregister temporarily stores the result of the shift operation until thecomplete result, Result[63:0] 860 can be transmitted to the DESTregister.

For a complete sixty-four bit packed shift circuit, eight shift unitsand seven bit control units are used. Such a circuit can also be used toperform a shift on a sixty-four bit unpacked data, thereby using thesame circuit to perform the unpacked shift operation and the packedshift operation.

Another Packed Shift Circuit

FIG. 9 illustrates another embodiment of a packed shift circuit. In oneembodiment, the packed shift circuit is capable of performing arithmeticshift operations on multiple data types. For example, the packed shiftcircuit may be capable of performing a packed shift on data elementswhich each contain one 64-bit value, two 32-bit data values, or four16-bit values. This embodiment may also be implemented to be capable ofalternatively or additionally performing logical shift operations, rightshifts, and/or left shifts.

A barrel shifter 905 is used to shift Source1 by the count specified inthe low order bits of Source2. However, if Source1 is a packed datatype, the barrel shifter shifts the low order bits of each of the valuesin the packed data type into the high order bits of the next lowestorder value to produce a shifted packed intermediate result. Acorrection circuit is used to replace each of these bits with the mostsignificant bit of the corresponding value if it is a signed shiftoperation, and a zero if it is a logical shift operation. In oneembodiment, if at least one of the high order bits that are not requiredto specify the shift count is one, all the bits of the shifted packedintermediate result are replaced with the sign bit (for right arithmeticshifts) or zero (for logical shifts). One embodiment of the barrelshifter 905 is described with reference to FIG. 10.

The shift data is driven on a Source1 bus 901. The shift count is drivenon a Source2 bus 902 in two portions, Source2[5:0], an actual shiftcount bus 903, Source2[63:6], and an overflow shift count bus 904. Thesix bits required to specify a shift count ranging from 0 to 63 arespecified on the actual shift count bus 903. The rest of the 64-bit datafield is specified on the overflow shift count bus 904. The Source1 bus901, the actual shift count bus 903, and a left shift bus 900 arecoupled to the inputs of the barrel shifter 905. In one embodiment, thebarrel shifter 905 contains a set of muxes that use complex gates(described below) to drive a set of 16-1 muxes which form one stage ofthe barrel shifter 905. The barrel shifter 905 drives a shift output bus919.

Muxes 906-909 drive the replacements bits that are used to correct theappropriate bits of a shift output bus 914. Each of the muxes 906-909corresponding to the most-significant to the least significant word ofthe shift output bus 914, respectively. A right-shift arithmeticdoubleword (rsadword) bus 928 is coupled to the most-significant selectbit of each of the muxes 906-909 to indicate whether the shift operationis an arithmetic right shift that operated on packed doubleword data. Aright-shift arithmetic word (rsaword) bus 929 is coupled to theleast-significant select bit of each of the muxes 906-909 to indicatewhether the shift operation is an arithmetic right shift that operatedon packed word data. The rsadword signal and the rsaword signal may begenerated based on the decoding of the control signal 207, for example.A zero is driven through a set of zero busses 924-927 which are coupledto the zero input of each of the muxes 906-909, respectively. A zero isused to correct the selected bits on the shift output bus 919 when theoperation is neither a right shift arithmetic word or right shiftarithmetic doubleword operation. The operation may be a left shift or alogical shift, for example. When the operation is a rsaword operation,the most significant bit of each word (the sign bit) is used to correctthe selected bit of each corresponding word of the shifted packedintermediate result on the shift output bus 919. A Source1[63] bus 920,a Source1[47] bus 921, a Source1[31] bus 922, and a Source1[15] bus 923are coupled to the corresponding 1 inputs of each of the muxes 906-909,respectively. The sign bit of each of the words of the packed word dataare driven onto the corresponding bus. When the operation is a rsadwordoperation, the most significant bit of each doubleword (the sign bit) isused to correct the selected bits of each corresponding doubleword ofthe shifted packed intermediate result on the shift output bus 919. TheSource1[63] bus 920 and the Source1[31] bus 922 are coupled to thecorresponding two inputs of muxes 906-907 and muxes 908-909,respectively. The sign bit of each of the corresponding doublewords isdriven onto the corresponding bus. Each of the muxes 906-909 drives acorresponding replacement bit bus 996-999.

The actual shift count bus 903 is also coupled to the input of aless-than-or-equal-to (<=) decoder logic 930 which drives a 64-bitdecoded signal on the decoded bus 938. The decoded signal is a field ofzeroes with ones in the bit positions corresponding to numbers less thanor equal to the value on the actual shift count bus 903. The bits thatare one correspond to the bit positions of the shift output bus thatshould be corrected if the operation were a left shift of a 64-bitscalar data. The value on the decoded bus 938 is received andmanipulated by a fixshift circuit 932 to produce the values on thefixdata busses 934-937 according to the operation and data typespecified on the control bus 933 such that the appropriate bits of eachvalue of the shifted packed intermediate result are corrected. Forexample, if a right shift of packed word data were indicated on thecontrol bus 933 and a shift count of 6 was indicated on the actual shiftcount bus 903, the fixshift circuit 932 would replicate theleast-significant 6 ones produced on the 64-bit decoded bus 938 on themost-significant 6 bits of each of the 16-bit fixdata busses 934-937.Alternatively, if a left shift of packed word data were indicated on thecontrol bus 933 and a shift count of 6 was indicated on the actual shiftcount bus 903, the fixshift circuit 932 would replicate theleast-significant 6 ones produced on the 64-bit decoded bus 938 on theleast-significant 6 bits of each of the 16-bit fixdata busses 934-937.The overflow shift count bus 904 is input to NOR logic 931 whichproduces an output on the NOR bus 939 that is one only if all the bitsof the Source2[63:6] bus 904 are zero. When the NOR bus 939 is low, theFixshift circuit 932 indicates that all bits should be replaced. Moredetails of the Fixshift circuit 932 is provided below.

Each of the bits of the most significant word of the shift output bus919 (S_(O)[63:48]) are coupled to the zero input of a corresponding oneof the set of muxes 910. The replacement bit bus 996 which correspondsto the replacement bit for the most significant word is coupled to theone input of each of the set of muxes 910. Each bit of the fixdata bus934 is coupled to the corresponding one of the set of muxes 910 toindicate whether the corresponding bit of the S_(O)[63:48] data or thecorresponding bit on the replacement bit bus 996 is driven onto acorresponding bit of the fixed shift output (FS_(O)[63:48]) bus. Theinputs and outputs of muxes 911-913 are similarly coupled, asillustrated in FIG. 9.

While FIG. 9 illustrates one circuit for implementation of a shiftercircuit, any number of well-known shifter circuits providing theequivalent function may be used.

Fixshift Circuit

FIG. 10 illustrates one embodiment of the fixshift circuit 932. Thecontrol bus 933 comprises a left-shift word (lsw) bus 1000, aright-shift word doubleword (rswd) bus 1001, a left-shift doublewordquadword (lsdq) bus 1002, a left-shift word doubleword quadword (lswdq)bus 1003, a right-shift word (rsw) bus 1004, a right-shift doubleword(rsd) bus 1005, a right-shift quadword (rsq) bus 1006, a left-shiftdoubleword (lsd) bus 1007, a right-shift word doubleword quadword(rswdq) bus 1008, a left-shift word doubleword (lswd) bus 1009, aright-shift doubleword quadword (rsdq) bus 1010, and a left-shiftquadword (lsq) bus 1011. These signals may be generated based on thedecoding of the control signal 207, for example. The names of theindividual control signals indicate when they are asserted (active).These signals are a one when they are active (active high). For example,the lsw bus 1000 is only active when the operation is a left-shift of apacked word data. The rswd bus 1001 is only active when the operation isa right-shift operation of a packed word data or a packed doubleworddata. Each of the busses of the control bus 933 are coupled to acorresponding one of inverters 1020-1031 which drive one of thecorresponding busses comprising an lsw# bus 1040, an rswd# bus 1041, anIsdq# bus 1042, an lswdq# bus 1043, an rsw# bus 1044, an rsd# bus 1045,an rsq# bus 1046, an Isd# bus 1047, an rswdq# bus 1048, an Iswd# bus1049, an rsdq# bus 1050, and an Isq# bus 1051, respectively. Thesesignals are zero when they are active (active low).

Each of a set of muxes 1060 drives a bit of the fixdata bus 937 toindicate which bits of the least significant word of the shift outputbus 919 (referring to FIG. 9) should be replaced. The lswdq# bus 1043 iscoupled to the select 0 input of each of the set of muxes 1060 to selecteach data 0 input whenever the operation is a left-shift of either aword, doubleword, or quadword. Each bit of the least significant word ofthe decoded bus 938 is coupled to a corresponding data input 0 of eachof the set of muxes 1060. For example, the three least significant bitsof the fixdata bus 937 would indicate that the three least significantbits of the least significant word of the shift output bus 919(referring to FIG. 9) should be replaced for a lswdq with a shift countof 3. The rsw# bus 1044 is coupled to the select 1 input of each of theset of muxes 1060 to select each data 1 input whenever the operation isa right-shift of a word. Each bit of the least significant word of thedecoded bus 938 is coupled to a corresponding data input 1 of each ofthe set of muxes 1060 in reverse order (The most significant bit of thedecoded bus 938 drives the one of the set of muxes 1060 that drives theleast significant bit of the fixdata bus 937, the second mostsignificant bit of the decoded bus 938 drives the one of the set ofmuxes 1060 that drives the second least significant bit of the fixdatabus 937, etc.). For example, the three most significant bits of thefixdata bus 937 would indicate that the three least significant bits ofthe least significant word of the shift output bus 919 (referring toFIG. 9) should be replaced for a rsw with a shift count of 3. The rsd#bus 1045 is coupled to the select 2 input of each of the set of muxes1060 to select each data 2 input whenever the operation is a right-shiftof a doubleword. Each bit of the second least significant word of thedecoded bus 938 is coupled to a corresponding data input 2 of each ofthe set of muxes 1060 in reverse order. For example, the three mostsignificant bits of the fixdata bus 937 would indicate that the threeleast significant bits of the least significant word of the shift outputbus 919 (referring to FIG. 9) should be replaced for a rsd with a shiftcount of 19. The right shift shifts through the most significant word ofthe least significant doubleword before it begins to effect the leastsignificant word. The rsq# bus 1046 is coupled to the select 3 input ofeach of the set of muxes 1060 to select each data 3 input whenever theoperation is a right-shift of a quadword. Each bit of the mostsignificant word of the decoded bus 938 is coupled to a correspondingdata input 3 of each of the set of muxes 1060 in reverse order. Forexample, the three most significant bits of the fixdata bus 937 wouldindicate that the three least significant bits of the least significantword of the shift output bus 919 (referring to FIG. 9) should bereplaced for a rsq with a shift count of 51. The right shift shiftsthrough the most significant 48 bits of the quadword before it begins toeffect the least significant word.

The lswdq bus 1003, the rsw bus 1004, the rsd bus 1005, and the rsq bus1006 are coupled to a NOR gate 1013 which drives a zero bus 1017. Thezero bus 1017 is coupled to the control 0 (c0) input of each of the setof muxes 1060 to force a zero on all the bits of the fixdata bus 937when none of the select inputs are active. In addition the NOR bus 939is coupled to the control 1 (c1) input of each of the muxes to force aone on all the bits of the fixdata bus 937 when at least one of themost-significant bits on the overflow shift count bus 904 is non-zero.This forces all the bits of the shifted packed intermediate result onthe shift output bus 719 to be replaced. This produces a result that isconsistent with a Source1 value that is extended beyond the mostsignificant and least significant bits of the register. If such a valueis shifted by greater than the register size, the sign bit (for rightarithmetic shifts) or the zero bits (for logical shifts) should replacethe whole field.

Each of a set of muxes 1061 drives a bit of the fixdata bus 936 toindicate which bits of the second least significant word of the shiftoutput bus 919 (referring to FIG. 9) should be replaced. The lsw# bus1040 is coupled to the select 0 input of each of the set of muxes 1061to select each data 0 input whenever the operation is a left-shift of aword. Each bit of the least significant word of the decoded bus 938 iscoupled to a corresponding data input 0 of each of the set of muxes1061. For example, the three least significant bits of the fixdata bus936 would indicate that the three least significant bits of the secondleast significant word of the shift output bus 919 (referring to FIG. 9)should be replaced for a lsw with a shift count of 3. The rswd# bus 1041is coupled to the select 1 input of each of the set of muxes 1061 toselect each data 1 input whenever the operation is a right-shift of aword or a doubleword. Each bit of the least significant word of thedecoded bus 938 is coupled to a corresponding data input 1 of each ofthe set of muxes 1061 in reverse order. For example, the three mostsignificant bits of the fixdata bus 936 would indicate that the threeleast significant bits of the second least significant word of the shiftoutput bus 919 (referring to FIG. 9) should be replaced for a rswd witha shift count of 3. The Isdq# bus 1042 is coupled to the select 2 inputof each of the set of muxes 1061 to select each data 2 input wheneverthe operation is a left-shift of a doubleword or a quadword. Each bit ofthe second least significant word of the decoded bus 938 is coupled to acorresponding data input 2 of each of the set of muxes 1061. Forexample, the three least significant bits of the fixdata bus 936 wouldindicate that the three least significant bits of the second leastsignificant word of the shift output bus 919 (referring to FIG. 9)should be replaced for a lsdq with a shift count of 19. The left shiftshifts through the least significant word before it begins to effect thesecond least significant word. The rsq# bus 1046 is coupled to theselect 3 input of each of the set of muxes 1061 to select each data 3input whenever the operation is a right-shift of a quadword. Each bit ofthe second most significant word of the decoded bus 938 is coupled to acorresponding data input 3 of each of the set of muxes 1061 in reverseorder. For example, the three most significant bits of the fixdata bus936 would indicate that the three least significant bits of the secondleast significant word of the shift output bus 919 (referring to FIG. 9)should be replaced for a rsq with a shift count of 35. The right shiftshifts through the most significant doubleword of the quadword before itbegins to effect the second least significant word.

The lsw bus 1000, the rswd bus 1001, the lsdq bus 1002, and the rsq bus1006 are coupled to a NOR gate 1012 which drives a zero bus 1016. Thezero bus 1016 is coupled to the control 0 (c0) input of each of the setof muxes 1061 to force a zero on all the bits of the fixdata bus 936when none of the select inputs are active. In addition the NOR bus 939is coupled to the control 1 (c1) input of each of the muxes to force aone on all the bits of the fixdata bus 936 when at least one of themost-significant bits on the overflow shift count bus 904 is non-zero.This forces all the bits of the shifted packed intermediate result onthe shift output bus 719 to be replaced.

Each of a set of muxes 1062 drives a bit of the fixdata bus 935 toindicate which bits of the second most significant word of the shiftoutput bus 919 (referring to FIG. 9) should be replaced. The lswd# bus1049 is coupled to the select 0 input of each of the set of muxes 1062to select each data 0 input whenever the operation is a left-shift ofeither a word or doubleword. Each bit of the least significant word ofthe decoded bus 938 is coupled to a corresponding data input 0 of eachof the set of muxes 1062. For example, the three least significant bitsof the fixdata bus 935 would indicate that the three least significantbits of the second most significant word of the shift output bus 919(referring to FIG. 9) should be replaced for a lswd with a shift countof 3. The rsw# bus 1044 is coupled to the select 1 input of each of theset of muxes 1062 to select each data 1 input whenever the operation isa right-shift of a word. Each bit of the least significant word of thedecoded bus 938 is coupled to a corresponding data input 1 of each ofthe set of muxes 1060 in reverse order. For example, the three mostsignificant bits of the fixdata bus 935 would indicate that the threeleast significant bits of the second most significant word of the shiftoutput bus 919 (referring to FIG. 9) should be replaced for a rswd witha shift count of 3. The rsdq# bus 1050 is coupled to the select 2 inputof each of the set of muxes 1062 to select each data 2 input wheneverthe operation is a right-shift of a doubleword or quadword. Each bit ofthe second least significant word of the decoded bus 938 is coupled to acorresponding data input 2 of each of the set of muxes 1062 in reverseorder. For example, the three most significant bits of the fixdata bus935 would indicate that the three least significant bits of the secondmost significant word of the shift output bus 919 (referring to FIG. 9)should be replaced for a rsdq with a shift count of 19. The right shiftshifts through the most significant word before it begins to effect thesecond least significant word. The lsq# bus 1051 is coupled to theselect 3 input of each of the set of muxes 1062 to select each data 3input whenever the operation is a left-shift of a quadword. Each bit ofthe second most significant word of the decoded bus 938 is coupled to acorresponding data input 3 of each of the set of muxes 1062 in reverseorder. For example, the three most significant bits of the fixdata bus935 would indicate that the three least significant bits of the secondmost significant word of the shift output bus 919 (referring to FIG. 9)should be replaced for a lsq with a shift count of 35. The left shiftshifts through the least significant doubleword before it begins toeffect the second most significant word.

The lsw bus 1000, the rsw bus 1004, the rsdq bus 1010, and the lsq bus1011 are coupled to a NOR gate 1014 which drives a zero bus 1018. Thezero bus 1018 is coupled to the control 0 (c0) input of each of the setof muxes 1062 to force a zero on all the bits of the fixdata bus 935when none of the select inputs are active. In addition the NOR bus 939is coupled to the control 1 (c1) input of each of the muxes to force aone on all the bits of the fixdata bus 935 when at least one of themost-significant bits on the overflow shift count bus 904 is non-zero.This forces all the bits of the shifted packed intermediate result onthe shift output bus 719 to be replaced.

Each of a set of muxes 1063 drives a bit of the fixdata bus 934 toindicate which bits of the most significant word of the shift output bus919 (referring to FIG. 9) should be replaced. The lsw# bus 1000 iscoupled to the select 0 input of each of the set of muxes 1063 to selecteach data 0 input whenever the operation is a left-shift of a word. Eachbit of the least significant word of the decoded bus 938 is coupled to acorresponding data input 0 of each of the set of muxes 1063. Forexample, the three least significant bits of the fixdata bus 934 wouldindicate that the three least significant bits of the most significantword of the shift output bus 919 (referring to FIG. 9) should bereplaced for a lsw with a shift count of 3. The lsd# bus 1047 is coupledto the select 1 input of each of the set of muxes 1063 to select eachdata 1 input whenever the operation is a left-shift of a doubleword.Each bit of the least significant word of the decoded bus 938 is coupledto a corresponding data input 1 of each of the set of muxes 1063. Forexample, the three least significant bits of the fixdata bus 934 wouldindicate that the three least significant bits of the most significantword of the shift output bus 919 (referring to FIG. 9) should bereplaced for a lsd with a shift count of 19. The left shift shiftsthrough the second least significant word before it begins to effect themost significant word. The rswdq# bus 1048 is coupled to the select 2input of each of the set of muxes 1063 to select each data 2 inputwhenever the operation is a right-shift of a word, doubleword, orquadword. Each bit of the least significant word of the decoded bus 938is coupled to a corresponding data input 2 of each of the set of muxes1063 in reverse order. For example, the three most significant bits ofthe fixdata bus 934 would indicate that the three least significant bitsof the most significant word of the shift output bus 919 (referring toFIG. 9) should be replaced for a rswdq with a shift count of 3. The lsq#bus 1045 is coupled to the select 3 input of each of the set of muxes1063 to select each data 3 input whenever the operation is a left-shiftof a quadword. Each bit of the most significant word of the decoded bus938 is coupled to a corresponding data input 3 of each of the set ofmuxes 1060. For example, the three most significant bits of the fixdatabus 934 would indicate that the three least significant bits of the mostsignificant word of the shift output bus 919 (referring to FIG. 9)should be replaced for a lsq with a shift count of 51. The left shiftshifts through the least significant 48 bits of the quadword before itbegins to effect the most significant word.

The lsw bus 1000, the lsd bus 1007, the rswdq bus 1008, and the lsq bus1011 are coupled to a NOR gate 1015 which drives a zero bus 1019. Thezero bus 1019 is coupled to the control 0 (c0) input of each of the setof muxes 1063 to force a zero on all the bits of the fixdata bus 934when none of the select inputs are active. In addition the NOR bus 939is coupled to the control 1 (c1) input of each of the muxes to force aone on all the bits of the fixdata bus 934 when at least one of themost-significant bits on the overflow shift count bus 904 is non-zero.This forces all the bits of the shifted packed intermediate result onthe shift output bus 719 to be replaced.

While FIG. 10 illustrates one circuit for implementation of the fixshiftcircuit 932 of FIG. 9, any number of alternative fixshift circuits couldbe used.

Barrel Shifter

FIG. 11 illustrates one embodiment of the barrel shifter 905 (referringto FIG. 9). The barrel shifter 905 is implemented to perform rightshifts. In order to perform left shifts, a right shift of the two'scomplement of the right shift count is performed according to well-knownmethods. The actual shift count bus 903 comprises an Source2[0] bus1100, an Source2[1] bus 1101, an Source2[2] bus 1102, an Source2[3] bus1103, an Source2[4] bus 1104, and an Source2[5] bus 1105. The Source2[1]bus 1101 and the shift left bus 900 are coupled to logic 1110 whichgenerates a signal on select bus 1120 that is the value of Source2[1]when the operation is a right shift and the complement of Source2[1]when the operation is a left shift. The select bus 1120 is coupled tothe select input of a set of 2-1 Muxes 1140. The Source1[63:0] bus 901is coupled to circuit 1161 which replicates the 64-bit data to produce a128-bit data (where one copy of the 64-bit data is in the mostsignificant quadword and the other is in the least significant quadword)on the data[127:0] bus 1130. In one embodiment, the circuit 1161 issimply wires that branch each single bit input to two output bits at theappropriate bit positions. Each bit of the data[127:2] portion of thedata[127:0] bus 1130 is coupled to each corresponding 1 input of the setof 2-1 Muxes 1140. Each bit of the data[125:0] portion of thedata[127:0] bus 1130 is coupled to each corresponding 0 input of the setof 2-1 Muxes 1140. The set of 2-1 Muxes 1140 are coupled tocorresponding bits of an intermediate result bus 1141. When the selectbus 1120 is driven high, data [127:2] is driven onto the intermediateresult bus 1141 thereby shifting the data by two positions. When theselect bus 1120 is driven low, data [125:0] is driven onto theintermediate result bus 1141.

The next stage of the barrel shifter 905 shifts the data on theintermediate result bus 1141 by 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40,44, 48, 52, 56, or 60 positions depending on the value of the bits onthe Source2[2] bus 1102, the Source2[3] bus 1103, the Source2[4] bus1104 and the Source2[5] bus 1105. The Source2[2] bus 1102 is coupled tologic 1111 (described in more detail below) which drives the two bits ofthe bitpair bus 1121. The first bit is Source2[2] when the operation isa right shift and the complement of Source2[2] when the operation is aleft shift. The second bit is the complement of the first bit. TheSource2[3] bus 1103, the Source2[4] bus 1104, and the Source2[5] bus1105 are coupled to logic circuits 1112-1114, respectively, which drivebitpair busses 1122-1124, respectively, in a similar manner. The bitpairbusses 1121-1124 are coupled to the inputs of decoder 1116 thatgenerates a decoded value of the bitpair busses 1121-1124 on the selectbus 1162 according to well-known methods. Each bit of the intermediateresult [65:0] portion of the intermediate result bus 1141 is coupled tothe 0 inputs of the corresponding one of the set of 16-1 Muxes 1150.Each bit of the intermediate result [69:4] portion of the intermediateresult bus 1141 is coupled to the 1 inputs of the corresponding one ofthe set of 16-1 Muxes 1150. Each bit of the intermediate result [125:60]portion of the intermediate result bus 1141 is coupled to the 15 inputsof the corresponding one of the set of 16-1 Muxes 1150. The 2 inputsthrough the 14 inputs are coupled in a manner according to the patternillustrated in FIG. 11 and described above. The set of muxes 1150 drivean intermediate result bus 1151 according to the input selected by thedecoded value on the select bus 1162.

The last stage of the barrel shifter 905 shifts the data on theintermediate result bus 1151 by 0, 1, or 2 positions according to thevalue on the Source2[0] bus 1100 and the shift left bus 900. TheSource2[0] bus 1100 and the shift left bus 900 are coupled to the inputsof a logic circuit 1115 which drives the select bus 1125. The logiccircuit 1115 adds the values of the bits on the Source2[0] bus 1100 andthe shift left bus 900 and drives the decoded sum on the select bus 1125according to well-known methods. The select bus 1125 is coupled to a setof 3-1 Muxes 1160. Each bit of the intermediate result [63:0] portion ofthe intermediate result bus 1151 is coupled to the 0 inputs of thecorresponding one of the set of 3-1 Muxes 1160. Each bit of theintermediate result [64:1] portion of the intermediate result bus 1151is coupled to the 1 inputs of the corresponding one of the set of 3-1Muxes 1160. Each bit of the intermediate result [65:2] portion of theintermediate result bus 1151 is coupled to the 2 inputs of thecorresponding one of the set of 3-1 Muxes 1160. Each of the set of 3-1Muxes 1160 drives the corresponding bit of the result on the shiftedoutput bus 919 according to the input selected by the decoded sum on theselect bus 1125.

While FIG. 10 illustrates one circuit for implementation of the fixshiftcircuit 932 of FIG. 8, any number of alternative fixshift circuits couldbe used.

Encoding Logic

FIG. 12 illustrates one embodiment of the encoding logic represented inFIG. 11 as each of the logic circuits 1111-1114. A shift count bit isdriven onto the S bus 1220 (which corresponds to each of the first bitof a bitpair bus as described above) and the complement of the shiftcount bit is driven onto the S# bus (which corresponds to the second bitof a bitpair bus as described above) when the shift left bus 1203indicates that the operation is a right shift. The complement of theshift count bit is driven onto the S bus 1220 and the shift count bit isdriven onto the S# bus when the shift left bus 1203 indicates that theoperation is a left shift.

The shift count bit is driven on a shiftcount bit bus 1202 which iscoupled to the input of an inverter 1210. Inverter 1210 drives thecomplement of the shift count bit on the shiftcount bit# bus 1204 whichis coupled to the input of an inverter 1212. Inverter 1212 drives thebit to be encoded on a delayed shiftcount bit bus 1206. The shift leftbus 1203 is coupled to the input of inverter 1211 which drives thecomplement of the shift left signal on the shift left# bus 1205. Theshift left# bus 1205 is coupled to an inverter 1213 which drives thedelayed shift left bus 1207.

The shiftcount bit# bus 1204 is coupled to the first input of complexgate 1214 and the fourth input of complex gate 1215. The delayedshiftcount bus 1206 is coupled to the fourth input of complex gate 1214and the second input of complex gate 1215. The shift left# bus 1205 iscoupled to the third input of complex gate 1214 and the third input ofcomplex gate 1215. The delayed shift left bus 1207 is coupled to thefirst input of complex gate 1214 and the first input of complex gate1215.

Table 7 is the truth table for both complex gate 1214 and complex gate1215. The output is false whenever either the first two inputs are trueor the second two inputs are true. Otherwise, the output is false. Theimplementation of this logic as a complex gate improves performance.This is particularly important since the logic decodes 4 bits for thesecond stage of this 64-bit barrel shifter as compared to 3 bits for thesecond stage in a 32-bit barrel shifter.

TABLE 7 Complex Gate Truth Table First Second Third Fourth Input InputInput Input OUT 0 0 0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 1 0 0 1 0 1 01 1 0 1 1 0 1 0 1 1 1 0 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 1 0 1 1 0 1 1 0 00 1 1 0 1 0 1 1 1 0 0 1 1 1 1 0Method of Performing a Packed Shift Operation

FIG. 13 illustrates one embodiment of a method of performing a PackedShift Operation.

In Step 1301, a first packed data is accessed from a register or anothermemory, such as RAM, a cache memory, a flash memory, or other datastorage device. The first packed data represents multiple values to beshifted.

In Step 1302, a shift count is accessed from a register or anothermemory. The shift count represents the number of positions each value ofthe first packed data is to be shifted.

In Step 1303, the first packed data is shifted by the number ofpositions indicated by the shift count to produce an shifted packedintermediate result. In one embodiment, portions of some values of theshifted packed intermediate result may be shifted into other values ofthe shifted packed intermediate result.

In Step 1305, the correction circuit determines whether the shift countis greater than the number of bits to be shifted in the first packeddata. If so, Step 1306 is performed. If not Step 1307 is performed.

In Step 1306, all the bits of the shifted packed intermediate data isreplaced by the corresponding replacement bit. This produces a resultthat is consistent with a first packed data having values that areextended beyond the most significant and least significant bitsrepresented. If such a value is shifted by greater than the number ofbits represented, the sign bit (for right arithmetic shifts) or the zerobits (for logical shifts) should replace the whole value.

In Step 1307, at least one bit of the shifted packed intermediate datais replaced by the corresponding replacement bit. In one embodiment, thereplacement bits correspond to those bits in those portions of thevalues of the shifted packed intermediate result that are shifted intoother values of the shifted packed intermediate result.

Although a great deal of detail has been included in the description andfigures, the invention is defined by the scope of the claims. Onlylimitations found in the claims are considered essential to theinvention.

1. A digital processing apparatus comprising: a decoder to receive acontrol signal and to indicate a packed shift operation on a set of dataelements if the control signal includes a packed shift instructionformat operable to set a length of said data elements; and a functionalunit to shift a the set of data elements responsive to the packed shiftoperation, and to generate a first binary replacement digitcorresponding to a first data element of the set of data elements, thefirst data element having a first initial sign value, wherein the firstbinary replacement digit generated for the first data element is to filla high order binary digit of a shifted first data element with the firstinitial sign value or to fill a low order binary digit of the shiftedfirst data element with a zero value, and to produce the shifted firstdata element, the shifted first data element comprising the first binaryreplacement digit.
 2. The apparatus of claim 1 wherein the packedinstruction format comprises three or more bytes including a firstthree-bit source-destination identifier and a second three-bit sourceidentifier.
 3. The apparatus recited in claim 2 wherein said firstthree-bit source-destination identifier consists of bits three throughfive of said packed instruction format.
 4. The apparatus recited inclaim 3 wherein the second three-bit source identifier indicates amemory base address.
 5. The apparatus recited in claim 3 wherein thesecond three-bit source identifier can identify a source correspondingto an addressable storage location in memory that can store said secondsource operand.
 6. The apparatus recited in claim 3 wherein said secondthree-bit source identifier consists of a second source registeraddress.
 7. The apparatus of claim 6 wherein said second three-bitsource identifier comprises bits zero through two of said packedinstruction format.
 8. The apparatus recited in claim 2 wherein saidsecond three-bit source identifier can identify an immediate data valuecorresponding to said second source operand.
 9. The apparatus recited inclaim 8 wherein said second three-bit source identifier consists of bitsthree through five of said packed instruction format.
 10. The apparatusrecited in claim 9 wherein said first three-bit source-destinationidentifier consists of bits zero through two of said packed instructionformat.
 11. A processor comprising: a decoder operable to decode a firstinstruction, said instruction operable to specify a shift operation tobe performed on a first packed data sequence having a plurality ofpacked data elements, said first instruction further operable to specifya variable size of the data elements included in said packed datasequence; and a circuit coupled to said decoder, said circuit operableto shift said plurality of packed data elements independently, inresponse to said first instruction.
 12. The apparatus recited in claim11, said decoder to generate a first field of control bits indicating afirst number of bits less than or equal the variable data size for saidcircuit to shift said plurality of packed data elements, wherein saidfirst number of bits is equal to the variable data size whenever: thevariable data size specifies word data elements and the second sourceoperand has a value greater than fifteen; the variable data sizespecifies double word data elements and the second source operand has avalue greater than thirty-one; and the variable data size specifies bytedata elements and the second source operand has a value greater thanseven.
 13. The apparatus recited in claim 11, said decoder to generate asecond field of one or more select bits and comprising: a correctioncircuit coupled with said decoder to select, according to the secondfield of one or more select bits, a corresponding zero replacement bitfor each element of the plurality of packed data elements whenever theoperation type indicates a shift left operation.
 14. The apparatusrecited in claim 13, said correction circuit coupled with the decoder toselect, according to the second field of one or more select bits, acorresponding zero replacement bit for each element of the plurality ofpacked data elements whenever the operation type indicates a shift rightlogical operation.
 15. The apparatus recited in claim 13, saidcorrection circuit coupled with the decoder to select, according to thesecond field of one or more select bits, a corresponding signreplacement bit for each element of the plurality of packed dataelements whenever the operation type indicates a shift right arithmeticoperation.
 16. A computer-implemented method for shifting packed data,the method comprising: decoding a first instruction, the instructionspecifying a shift operation to be performed on a first packed datasequence having a first plurality of packed data elements, said firstinstruction further specifying a variable size of each packed dataelement included in said packed data sequence; and shifting said firstplurality of packed data elements independently.
 17. The method recitedin claim 16, comprising: generating a field of one or more select bitsaccording th the shift operation to be performed; and selecting,according to said field of one or more select bits, a corresponding zeroreplacement bit for each element of the first plurality of packed dataelements whenever the operation type indicates a shift left operation.18. The method recited in claim 17, further comprising: selecting,according to said field of one or more select bits, a corresponding zeroreplacement bit for each element of the first plurality of packed dataelements whenever the operation type indicates a shift right logicaloperation.
 19. The method recited in claim 17, further comprising:selecting, according to said field of one or more select bits, acorresponding sign replacement bit for each element of the firstplurality of packed data elements whenever the operation type indicatesa shift right arithmetic operation.
 20. The method recited in claim 16,comprising: generating a field of control bits indicating a number ofbits, less than or equal the variable size, to shift said firstplurality of packed data elements, wherein said number of bits is equalto the variable size whenever the variable size specifies word dataelements and a second source operand of said first instruction specifiesa shift value greater than fifteen.
 21. The method recited in claim 20,wherein said number of bits is equal to the variable size whenever thevariable size specifies double word data and the second source operandof said first instruction specifies a shift value greater thanthirty-one.
 22. The method recited in claim 20, wherein said number ofbits is equal to the variable size whenever the variable size specifiesbyte data elements and the second source operand of said firstinstruction specifies a shift value greater than seven.
 23. A systemcomprising: a memory to hold a plurality of data elements; a processorcomprising: a decoder operable to decode a first instruction of a packeddata instruction set, said instruction operable to specify a shiftoperation to be performed on a first packed data sequence having aplurality of packed data elements, said first instruction furtheroperable to specify a variable size of the data elements included insaid packed data sequence, and a circuit coupled to said decoder, saidcircuit operable to shift said plurality of packed data elementsindependently, in response to said first instruction; a bus coupled withthe processor to transmit data to and from the processor and to and fromthe memory; and an interface to couple the bus with one or more devicesto provide data to or receive data from the bus, said one or moredevices comprising an audio device selected from the group consisting ofan audio digitizing device, a sound recording device, a sound playbackdevice, a microphone, a digital-to-analog converter, and a speaker. 24.The system of claim 23 further comprising a storage device to store aplurality of instruction sequences including instructions of the packeddata instruction set, said storage device to couple with the bus totransmit instructions to the processor and to the memory, wherein theplurality of instruction sequences include at least an instructionsequence to manipulate audio.
 25. The system of claim 23 furthercomprising a storage device to store a plurality of instructionsequences including instructions of the packed data instruction set,said storage device to couple with the bus to transmit instructions tothe processor and to the memory, wherein the plurality of instructionsequences include at least an instruction sequence to perform voicerecognition.
 26. The system of claim 23, said decoder to generate afirst field of control bits indicating a first number of bits less thanor equal the variable size for said circuit to shift said plurality ofpacked data elements, and a second field of one or more select bits;said processor including: a correction circuit to produce a plurality ofdestination data elements corresponding to the plurality of packed dataelements, said correction circuit coupled with the decoder to select,according to the second field of one or more select bits, acorresponding replacement bit for each element of the plurality ofpacked data elements to correct a number of bits in each element of theplurality of destination data elements according to the first field ofcontrol bits.